package logic

import (
	"context"
	"errors"
	"video/mysql/model"

	"video/videorpc/internal/svc"
	"video/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVideoDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoDelLogic {
	return &VideoDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 视频管理
func (l *VideoDelLogic) VideoDel(in *videorpc.VideoDelRequest) (*videorpc.VideoDelResponse, error) {
	// todo: add your logic here and delete this line

	var video model.Video
	model.DB.Debug().Where("id = ?", in.VideoId).Find(&video)
	if video.ID == 0 {
		return nil, errors.New("该视频不存在,删除失败")
	}
	model.DB.Debug().Delete(&video)

	return &videorpc.VideoDelResponse{}, nil
}
